--#include "data\functions\Activity\Common\Rank.lua" once           --活动通用 排行榜

--[[初始化排行榜(暂不使用)
id, value, name

function InitCommonRank(rankName, numMax)
	local ranking = Ranking.getRanking( rankName )
	if not ranking then
		ranking = Ranking.add( rankName, numMax, 1, 10 )
		if ranking then
			if not Ranking.load(ranking, nil) then
				Ranking.addColumn(ranking, "name")
			end
			Ranking.addRef( ranking )
		end
	end
end
]]


function InitCommonRank( rankName, rankColumn, rankRowNum )
	Rank.Init(rankName, rankName, rankColumn, rankRowNum, 0)
end


--[[
获取排行榜的数量
]]
function GetCommonRankCount( rankName )
	local count = 0
	local ranking = Ranking.getRanking( rankName )
	if ranking then
		count = Ranking.getRankItemCount( ranking ) -- body
	end
	return count
end

--[[
获取排行榜的数量
]]
function GetCommonRankLimitCount( rankName, rankLimit )
	local count = 0
	local ranking = Ranking.getRanking( rankName )
	if ranking then
		count = Ranking.getRankItemCountByLimit( ranking, rankLimit ) -- body
	end
	return count
end

--[[
按名次获取value
]]
function GetCommonRankValueByIdx(rankIdx, rankName)
	--print("GetCommonRankValueById, rankName="..rankName..", actorId="..actorId)
	local ranking = Ranking.getRanking( rankName )
	if ranking then
		local item = Ranking.getItemFromIndex(ranking, rankIdx-1)
		if item then
			return Ranking.getPoint(item)
		end
	end
	return 0
end

--[[
按名次获取Id
]]
function GetCommonRankIdByIdx( rankIdx, rankName )
	local ranking = Ranking.getRanking( rankName )
	if ranking then
		local item = Ranking.getItemFromIndex(ranking, rankIdx-1)
		if item then
			return Ranking.getId(item)
		end
	end
	return 0
end

--如果排行榜不存在，必须返回nil，为无效数据，避免异常情况
function GetCommonRankColumnValueByIdx(rankIdx, rankName, colIdx)
	--print("GetCommonRankColumnValueByIdx, rankName="..rankName..", colIdx="..colIdx..", rankIdx="..rankIdx)
	local ranking = Ranking.getRanking( rankName )
	if ranking then
		--print("GetCommonRankColumnValue, has rank")
		local item = Ranking.getItemFromIndex(ranking, rankIdx-1)
		if item then	--已经榜上有名
			local colValue = Ranking.getSub(item, colIdx)
			--print("GetCommonRankColumnValue, colValue="..colValue)
			if colValue == "-" then
				return 0
			else
				local numValue = tonumber(colValue)
				--print("GetCommonRankColumnValue, numValue="..numValue)
				if numValue then
					return numValue		--返回数字
				else
					return colValue 	--返回字符串
				end
			end
		else
			return nil
		end
	end
	return nil
end

--[[
获取某个actor的 rankIdx和Value
]]
function GetCommonRankIdxAndValueDataById( actorId, rankName, rankLimit )
	local num 	= 0
	local idx 	= 0
	local ranking = Ranking.getRanking( rankName )
	if ranking then
		local item = Ranking.getItemPtrFromId( ranking, actorId)
		if item then
			num = Ranking.getPoint(item)
			if num < rankLimit then			--不达标
				idx = 0
			else
				idx = Ranking.getIndexFromPtr(item) + 1
			end
		end
	end
	return idx, num
end


function GetCommonRankValueById(actorId, rankName)
	--print("GetCommonRankValueById, rankName="..rankName..", actorId="..actorId)
	local ranking = Ranking.getRanking( rankName )
	if ranking then
		local item = Ranking.getItemPtrFromId( ranking, actorId)
		if item then
			return Ranking.getPoint(item)
		end
	end
	return 0
end

--[[
获取排行榜名次 1-N名
0-未上榜，N：第N名
C++返回（-1：未上榜，0-第1名， N-1 -第N名）
]]
function GetCommonRankIndexById(actorId, rankName)
	--print("GetCommonRankValueById, rankName="..rankName..", actorId="..actorId)
	local ranking = Ranking.getRanking( rankName )
	if ranking then
		 local index = Ranking.getItemIndexFromId( ranking, actorId) + 1
		 return index
	end
	return 0
end

--设置排行榜数据
function SetCommonRankValueById(actorId, rankName, newValue )
	local ranking = Ranking.getRanking( rankName )
	if ranking then
		local item = Ranking.getItemPtrFromId( ranking, actorId)
		if item then	--已经榜上有名
			Ranking.setItem(ranking, actorId, newValue)
		else	--新加的
			item = Ranking.addItem(ranking, actorId, newValue)
		end
	end
end

--增加、减少排行榜数据
function UpdateCommonRankValueById(actorId, rankName, addValue )
	local ranking = Ranking.getRanking( rankName )
	if ranking then
		local item = Ranking.getItemPtrFromId( ranking, actorId)
		if item then	--已经榜上有名(数值变化)
			if Ranking.updateItem(ranking, actorId, addValue) then
				return true
			end
		else	--新加的
			if Ranking.addItem(ranking, actorId, addValue) then
				return true
			end
		end
	end
	return false
end

--如果排行榜不存在，必须返回nil，为无效数据，避免异常情况
function GetCommonRankColumnValueById(actorId, rankName, colIdx)
	--print("GetCommonRankColumnValue, rankName="..rankName..", colIdx="..colIdx..", actorId="..actorId)
	local ranking = Ranking.getRanking( rankName )
	if ranking then
		--print("GetCommonRankColumnValue, has rank")
		local item = Ranking.getItemPtrFromId( ranking, actorId)
		if item then	--已经榜上有名
			local colValue = Ranking.getSub(item, colIdx)
			if colValue == "-" then
				return 0
			else
				local numValue = tonumber(colValue)
				--print("GetCommonRankColumnValue, numValue="..numValue)
				if numValue then
					return numValue		--返回数字
				else
					return colValue 	--返回字符串
				end
			end
		else
			return 0
		end
	end
	return nil
end

--设置排行榜的扩展数据
--colIdx：从1开始，0是name
--返回值：true-设置成功，false-设置失败
--在涉及到领取道具的时候，为了避免出现异常，必须判断一下返回值
function SetCommonRankColumnValueById(actorId, rankName, value, colIdx, newColValue)
	--print("SetCommonRankColumnValueById actorId="..actorId..", rankName="..rankName..
	--	", colIdx="..colIdx..", newColValue="..newColValue)
	local ranking = Ranking.getRanking( rankName )
	if ranking then
		local item = Ranking.getItemPtrFromId( ranking, actorId )
		if item then	--已经榜上有名
			Ranking.setSub(item, colIdx, newColValue)    --万一排行榜错误，这里不一定能设置成功
			if Ranking.getSub(item, colIdx) ~= tostring(newColValue) then  --列没有设置成功
				return false
			end
			return true
		else	--新加的
			item = Ranking.addItem(ranking, actorId, value)
			if item then
				Ranking.setSub(item, colIdx, newColValue)
				if Ranking.getSub(item, colIdx) ~= tostring(newColValue) then  --列没有设置成功
					return false
				end
				return true
			end
		end
	end
	return false
end

--[[
列的格式为{}
]]
function GetCommonRankColumnSubValueBySubIdx( actorId, rankName, colIdx, subIdx )
	local columnStr = GetCommonRankColumnValueById( actorId, rankName, colIdx) or {}
	if columnStr == 0 then
		columnStr = "{}"
	end
	local columnTable = BaseFuc_unserialize( columnStr )
	return columnTable[subIdx] or 0
end

--[[
列的格式为{}
]]
function SetCommonRankColumnSubValueBySubIdx( actorId, rankName, colIdx, subIdx, newSubValue )
	local columnStr = GetCommonRankColumnValueById( actorId, rankName, colIdx) or {}
	if columnStr == 0 then
		columnStr = "{}"
	end
	local columnTable = BaseFuc_unserialize( columnStr )
	columnTable[subIdx] = newSubValue
	local newColumnStr = BaseFuc_serialize( columnTable )
	return SetCommonRankColumnValueById( actorId, rankName, 0, colIdx, newColumnStr)
end


function SaveCommonRank(rankName)
	--print("SaveCommonRank, rankName="..rankName)
	local ranking = Ranking.getRanking( rankName )
	if ranking then
		Ranking.save(ranking, rankName, true)
	end
end

function CopyCommonRank(rankNameSrc, rankNameDes, bSave)
	--print("CopyCommonRank, rankNameSrc="..rankNameSrc..", rankNameDes="..rankNameDes)
	local rankingSrc = Ranking.getRanking( rankNameSrc )
	if rankingSrc then
		Ranking.save( rankingSrc, rankNameDes, bSave )
	end
end

--[[
将rankNameSrc的rankIdx之前的记录拷贝到rankNameDes
bSavePoint:是否保留point值， true-拷贝point，false-point清0
]]
function CopyCommonRankByRankIdx( rankNameSrc, rankNameDes, rankIdx, columnNum, bSavePoint )
	local rankingSrc = Ranking.getRanking( rankNameSrc )
	local rankingDesc= Ranking.getRanking( rankNameDes )
	if not rankingSrc or not rankingDesc then
		return
	end

	Ranking.clearRanking( rankingDesc )
	local nCount = Ranking.getRankItemCount( ranking )
	if nCount < rankIdx then
		nCount = rankIdx
	end

	for idx=1, nCount do
		local itemSrc = Ranking.getItemFromIndex(rankingSrc, idx-1)
		if itemSrc and columnNum then		--当前榜
			local actorId 	= Ranking.getId(itemSrc)
			local point 	= 0
			if bSavePoint then 		--
				point = Ranking.getPoint(itemSrc)
			end
			local itemDes   = Ranking.addItem(rankingDesc, actorId, point)
			--print("CopyCommonRankByRankIdx, actorId="..actorId..", point="..point)
			if itemDes then
				for colIdx=1, columnNum do
					local colValue = Ranking.getSub(itemSrc, colIdx-1)
					Ranking.setSub(itemDes, colIdx-1, colValue)
				end
			end
		end
	end
end


function ClearCommonRank(rankName)
	--print("ClearCommonRank, rankName="..rankName)
	local ranking = Ranking.getRanking( rankName )
	if ranking then
		Ranking.clearRanking(ranking)
		Ranking.save(ranking, rankName, true)
	end
end

function HasCommonRank( rankName )
	local ranking = Ranking.getRanking( rankName )
	if ranking then
		return true
	end
	return false
end

function RemoveCommonRankRecord( actorId, rankName )
	--print("RemoveCommonRankRecord, rankName="..rankName..", actorId="..actorId)
	local ranking = Ranking.getRanking( rankName )
	if ranking then
		Ranking.removeId(ranking, actorId)
	end
end

--[[
获取排名
>0:名次
0-未上榜（不达标也算）
]]
function GetCommonRankIdxAndPoint( actorId, rankName, rankLimit )
	--print("GetCommonRankIdxAndPoint, rankName="..rankName)
	local ranking = Ranking.getRanking(rankName)
	if not ranking then
		return 0
	end
	
	local rankIdx 	= 0
	local point 	= 0 
	local item = Ranking.getItemPtrFromId( ranking, actorId)
	if item then
		point = Ranking.getPoint(item) or 0
		if rankLimit and point < rankLimit then			--不达标未上榜
			rankIdx = 0
		else
			rankIdx = Ranking.getIndexFromPtr(item) + 1
		end
	end
	return rankIdx, point
end


-----------------------------------------------------通用排行榜---------------------------------------------------------------
--获取排行榜相关的功能配置
function GetCommonRankCfgByType( rankType )
	if rankType == enCommonRankType_MagicCityWeek then			    --魔域迷城
		return  MagicCityCfg.weekRank
	elseif rankType == enCommonRankType_SpaceTrialWeek then			--血域试炼
		return SpaceTrialCfg.weekRank
	elseif rankType == enCommonRankType_BossBattleField then		--BOSS战场
		return BossBattleFieldCfg.battleRank
	elseif rankType == enCommonRankType_CombineArena then			--合服擂台
		return CombineServerArenaCfg.arena.scoreRank
	elseif rankType == enCommonRankType_CombineBigFight then		--合度大乱斗
		return CombineServerArenaCfg.fight.scoreRank
	elseif rankType == enCommonRankType_AnswerToday then			--每周答题积分榜
		return AnswerRankAwardConfig.dailyRank
	elseif rankType == enCommonRankType_BloodFightWeek then			--血战到底周榜
		return BloodFightCfg.weekRank
	elseif rankType == enCommonRankType_SceneAnswer then			--答题活动积分榜（单次）
		return SceneAnswerConfig.sceneRank
	elseif rankType == enCommonRankType_SkyTower then			    --通天塔数据榜
		return SkyTowerCfg.rank	
	end
	return nil
end

--[[
设置一些玩家信息
参考结构
BloodFightRankColumn = 
{	
	{"name"},				--0，玩家Name
	{"serverId"},			--1，玩家ServerId(留空)
	{"job"},				--2，玩家职业
}

]]
function SetCommonRankActorData( rankName, actorId, actorName, job )
	if not rankName then
		return
	end
	--print("SetCommonRankActorData, rankName="..rankName..", actorId="..actorId..", job="..job)
	local nameColumnIdx = 0
	local jobColumnIdx  = 2
	SetCommonRankColumnValueById( actorId, rankName, 0, nameColumnIdx, actorName )
	SetCommonRankColumnValueById( actorId, rankName, 0, jobColumnIdx, job )
end

--[[排行榜数据（非发奖）
发送full排行榜数据
]]
function SendCommonRankColumnValueFull(sysarg, activiyId, rankName, rankLimit)
	--print("SendCommonRankColumnValueFull,  activiyId="..activiyId..", rankName="..rankName)
	local ranking = Ranking.getRanking( rankName )
	if not ranking then
		return 
	end

	local pack = DataPack.allocPacket(sysarg, enDefaultEntitySystemID, sSendCommonActivityRankDataFull)
	if (pack ~= nil) then
		local nCount = System.getRankLimitCount(rankName, rankLimit)
		if nCount > 10 then
			nCount = 10
		end
		--print("SendCommonRankColumnValueFull,     nCount="..nCount)
		DataPack.writeChar(pack, activiyId)
		DataPack.writeChar(pack, nCount)
		for idx=1, nCount do
			local item = Ranking.getItemFromIndex(ranking, idx-1)
			if item then		--当前榜
				local name 		= Ranking.getSub(item, 0)
				local serverId 	= tonumber(Ranking.getSub(item, 1))
				local sex		= tonumber(Ranking.getSub(item, 2))
				local vocation	= tonumber(Ranking.getSub(item, 3))
				local circle	= tonumber(Ranking.getSub(item, 4))
				local level		= tonumber(Ranking.getSub(item, 5))
				local modleId	= tonumber(Ranking.getSub(item, 6))
				local icon		= tonumber(Ranking.getSub(item, 7))
				local weaponId	= tonumber(Ranking.getSub(item, 8))
				local swingId	= tonumber(Ranking.getSub(item, 9))

				DataPack.writeShort(pack, idx)
				DataPack.writeString(pack, name)
				DataPack.writeUInt(pack, serverId)
				DataPack.writeChar(pack, sex)
				DataPack.writeChar(pack, vocation)
				DataPack.writeChar(pack, circle)
				DataPack.writeShort(pack, level)
				DataPack.writeShort(pack, modleId)
				DataPack.writeShort(pack, icon)
				DataPack.writeShort(pack, weaponId)
				DataPack.writeShort(pack, swingId)

				local num 	= Ranking.getPoint(item)
				--print("SendCommonRankColumnValueFull, idx="..idx..", name="..name..", num="..num..", weaponId="..weaponId..
				--	", swingId="..swingId..", sex="..sex..", modleId="..modleId)
			end
		end
		DataPack.flush(pack)
	end	
end

--[[下发本人某个排行榜的积分以及名次
]]
function SendCommonRankSelfData( sysarg, rankType )
	local rankCfg = GetCommonRankCfgByType( rankType )
	if not rankCfg then
		return
	end
	
	local rankName 	= rankCfg.rankName
	local rankLimit = rankCfg.rankLimit
	if not rankName then
		return
	end

	--print("SendCommonRankSelfData, rankType="..rankType..", rankName="..rankName)
	local ranking = Ranking.getRanking( rankName )
	if not ranking then
		return 
	end

	local point	= 0
	local idx 	= 0
	local actorId = Actor.getActorId(sysarg)
	local item = Ranking.getItemPtrFromId( ranking, actorId)
	if item then
		point = Ranking.getPoint(item)
		if point < rankLimit then			--不达标
			idx = 0
		else
			idx = Ranking.getIndexFromPtr(item) + 1
		end
	end

	--[[
	if 1<= flag and flag <= 4 then			--本人数据
		local actorId = Actor.getActorId(sysarg)
		local item = Ranking.getItemPtrFromId( ranking, actorId)
		if item then
			point = Ranking.getPoint(item)
			if point < rankLimit then			--不达标
				idx = 0
			else
				idx = Ranking.getIndexFromPtr(item) + 1
			end
		end
	else  --全服数据
		point = GetCommonRankPointsSum( sysarg, rankName, 0 )
	end
	]]

	local pack = DataPack.allocPacket(sysarg, enDefaultEntitySystemID, sSendCommonRankSelfData)
	if (pack ~= nil) then
		DataPack.writeChar(pack, rankType)
		DataPack.writeUInt(pack, point)
		DataPack.writeShort(pack, idx)
		DataPack.flush(pack)
		--print("SendCommonRankSelfData, rankType="..rankType..", point="..point..", idx="..idx)
	end
end

--[[
注意，如果传入rankCfg，则rankType要与rankCfg保持一致
]]
function SendCommonRankSimpleData(sysarg, rankType)
	--print("SendCommonRankSimpleData,  rankType="..rankType)
	local rankCfg = GetCommonRankCfgByType( rankType )
	if not rankCfg then
		return
	end

	local rankName 		= rankCfg.rankName
	local displayLimit	= rankCfg.displayLimit			--显示要求积分（如无则使用rankLimit）
	local rankLimit 	= rankCfg.rankLimit 			--发奖要求积分
	local displayCount	= rankCfg.displayCount

	if not rankName then
		return
	end
	--print("SendCommonRankSimpleData,  rankName="..rankName)
	local ranking = Ranking.getRanking( rankName )
	if not ranking then
		return 
	end

	local pack = DataPack.allocPacket(sysarg, enDefaultEntitySystemID, sSendCommonRankSimpleData)
	if pack then
		local nCount = 0
		if displayLimit then
			--print("SendCommonRankSimpleData,  displayLimit="..displayLimit)
			nCount = Ranking.getRankItemCountByLimit( ranking, displayLimit )
		else
			nCount = Ranking.getRankItemCountByLimit( ranking, rankLimit )
		end
		if nCount > displayCount then
			nCount = displayCount
		end
		--print("SendCommonRankSimpleData,  nCount="..nCount)
		DataPack.writeChar(pack, rankType)
		DataPack.writeChar(pack, nCount)
		for idx=1, nCount do
			local item = Ranking.getItemFromIndex(ranking, idx-1)
			if item then		--当前榜
				local actorId 	= Ranking.getId(item)
				local point 	= Ranking.getPoint(item)
				local name 		= Ranking.getSub(item, 0)
				local serverId 	= tonumber(Ranking.getSub(item, 1))	or 0	--用于跨服排行榜
				local vocation	= tonumber(Ranking.getSub(item, 2))	or 0	--职业
				local param1	= tonumber(Ranking.getSub(item, 3)) or 0
				local param2	= tonumber(Ranking.getSub(item, 4)) or 0

				DataPack.writeShort(pack, idx)
				DataPack.writeUInt(pack, actorId)
				DataPack.writeUInt(pack, point)
				DataPack.writeString(pack, name)
				DataPack.writeChar(pack, vocation)
				DataPack.writeUInt(pack, param1)
				DataPack.writeUInt(pack, param2)
				--print("SendCommonRankSimpleData, idx="..idx..", name="..name..", point="..point..", serverId="..serverId..
				--	", vocation="..vocation..", param1="..param1)
			end
		end
		DataPack.flush(pack)
	end

	SendCommonRankSelfData( sysarg, rankType )		--本人名次也下发
end

--[[
通用排行榜，发奖
rankType：
取值于：
enum enCommonRankType
{
	enCommonRankType_No					= 0,				//占位
	enCommonRankType_MagicCityWeek		= 1,				//魔域迷城周榜
	enCommonRankType_SpaceTrialWeek		= 2,				//血域试炼周榜
	enCommonRankType_BossBattleField	= 3,				//BOSS战场伤害排行榜
	enCommonRankType_CombineArena		= 4,				//合服擂台积分榜
	enCommonRankType_CombineBigFight	= 5,				//合服大乱斗积分榜
	enCommonRankType_Max,									//
}

rankCfg:排名奖励，包括排行榜名称等，如果为nil，则通过rankType取排名奖励的配置
joinAwardCfg：参与奖，为nil则没有参与奖励，
]]
function SendCommonRankAwards( rankType, joinAwardCfg )
	--print("SendCommonRankAwards, rankType="..rankType)
	local rankCfg = GetCommonRankCfgByType( rankType )
	if not rankCfg then
		return
	end

	local rankName 		= rankCfg.rankName
	local rankNameHis 	= rankCfg.rankNameHis
	local rankLimit 	= rankCfg.rankLimit or 0
	local rankAwards 	= rankCfg.rankAwards
	local displayCount	= rankCfg.displayCount or 50
	if not rankName then
		return
	end

	--print("SendCommonRankAwards, rankName="..rankName)
	local ranking = Ranking.getRanking( rankName )
	if not ranking then
		return 
	end

	if not rankAwards then
		return
	end

	local nCount = Ranking.getRankItemCountByLimit( ranking, rankLimit )
	--[[这里不需要，按发奖配置数据
	if nCount > displayCount then
		nCount = displayCount
	end
	]]

	--print("SendCommonRankAwards,  nCount="..nCount)
	for idx=1, nCount do
		local item = Ranking.getItemFromIndex(ranking, idx-1)
		if item then		--当前榜
			local actorId 	= Ranking.getId(item)
			if actorId > 0 then
				local point 	= Ranking.getPoint(item)
				local rankAward = GetElemByCond( rankAwards, idx )				         --获取名次奖励
				if rankAward then		--有对应排名的奖励，才发奖
					local doAward 	= GetElemByOpenServerDay( rankAward.awards )		 --根据开服天数获取具体奖品
					local mailCont  = string.format( rankCfg.mailContent, point, idx )
					Awards.GiveToMailById( actorId, doAward.award, rankCfg.mailTitle, mailCont, rankCfg.mailLogId, rankCfg.mailLogStr )
				    --print("SendCommonRankAwards,  actorId="..actorId..", point="..point..", idx="..idx)
				elseif joinAwardCfg then	--没有排行奖励，就发参与奖励
					local doJoinAward = GetElemByOpenServerDay( joinAwardCfg.joinAwards )		 --根据开服天数获取具体奖品
					local mailCont  = string.format( joinAwardCfg.mailContent, point )
					Awards.GiveToMailById( actorId, doJoinAward.award, joinAwardCfg.mailTitle, mailCont, joinAwardCfg.mailLogId, joinAwardCfg.mailLogStr )
				end
			end
		end
	end

	--print("SendCommonRankAwards, rankNameHis="..rankNameHis)
	if rankNameHis then
		CopyCommonRank( rankName, rankNameHis, true )			--保存到历史榜中
	end

	if not rankCfg.notClearRank then		--需要清空排行榜
		ClearCommonRank( rankName )
	end
end

--[[
每日充值、消费数据清空，并发送客户端
]]
function ClearCommonDailyChargeAndCounsume( sysarg )
	Actor.setDailyChargeYuanBao( sysarg, 0)						--当日充值元宝清0
	Actor.setDailyConsumeYuanBao( sysarg, 0 )					--当日消费元宝清0
	Actor.setDailyChargeSingleYuanBao( sysarg, 0 )				--当日单笔最大充值元宝清0
	SendCommonDailyChargeAndCounsume( sysarg )
end

--[[
关闭排行榜面板
]]
function CloseCommonRankPanel( sysarg, rankType )
	local pack = DataPack.allocPacket(sysarg, enDefaultEntitySystemID, sCloseCommonRankPanel)
	if pack then
		DataPack.writeUInt(pack, rankType)
		DataPack.flush(pack)
	end
end

--[[
获取第N名的name和point
rankIdx：>0-第N名
]]
function GetCommonRankIdxNameAndValue( rankType, rankIdx )
	--print("GetCommonRankIdxNameAndValue, rankType="..rankType)
	local rankCfg = GetCommonRankCfgByType( rankType )
	if not rankCfg then
		return nil, 0
	end
	
	local rankName 	= rankCfg.rankName
	if not rankName then
		return nil, 0
	end

	local name 	= nil
	local value = 0
	if rankIdx > 0 then
		name = GetCommonRankColumnValueByIdx(rankIdx, rankName, 0 )			--column 0:Name
		--print("GetCommonRankIdxNameAndValue, name="..name)
		if name == 0 or name == "-" then
			name = nil
		end
		value = GetCommonRankValueByIdx(rankIdx, rankName) or 0
		--print("GetCommonRankIdxNameAndValue, value="..value)
		if value < rankCfg.rankLimit then 			--必须要达标才算
			return nil, 0
		end
	end
	return name, value
end

function GetCommonRankActorIdxAndValue( rankType, actorId )
	local rankCfg = GetCommonRankCfgByType( rankType )
	if not rankCfg then
		return 0, 0
	end
	
	local rankName 	= rankCfg.rankName
	local rankLimit = rankCfg.rankLimit or 0
	if not rankName then
		return 0, 0
	end
	local rankIdx, rankPoint = GetCommonRankIdxAndValueDataById( actorId, rankName, rankLimit )
	return rankIdx, rankPoint
end

-----------------------------------通用排行榜相关--------end------------------------------------------------------
